using System;
using System.Collections.Generic;

namespace OS_pre
{
    public class FakeBuffer
    {
        // buffer最大容量
        private int max;
        private Random _random = Form1._random;
        private List<object> itemList = new List<object>();

        public FakeBuffer(int max, int num)
        {
            this.max = max;
            for (int i = 0; i < num; i++)
            {
                itemList.Add(GetRandomItem());
            }
        }

        // 获取当前buffer容量
        public int GetCapacity()
        {
            return max - itemList.Count;
        }

        // 向buffer中增加一个数据
        public void Add(object o)
        {
            if (GetCapacity() != 0)
            {
                itemList.Add(o);
            }
        }

        // 从buffer中取走一个数据
        public void Take()
        {
            if (itemList.Count == 0)
            {
                return ;
            }
            object item = itemList[0];
            itemList.RemoveAt(0);
            // return item;
        }

        private object GetRandomItem()
        {
            char[] content =
            {
                '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                'a', 'b', 'c', 'd', 'e', 'f', 'g',
                'h', 'i', 'j', 'k', 'l', 'm', 'n',
                'o', 'p', 'q', 'r', 's', 't',
                'u', 'v', 'w', 'x', 'y', 'z',
                '[', ']', ';', '@', '#', '$', '%', '^', '&', '*', '(', ')'
            };
            return content[_random.Next(48)];
        }

        public string GetQueueItem()
        {
            string content = "";
            for (int i = 0; i < itemList.Count; i++)
            {
                content += itemList[i] + "    ";
            }

            return content;
        }
    }
}